﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;

namespace QLKhoaLuanCNTT.Models
{
    public class MD5Hash
    {
        /// <summary>
        /// Ham nay voi muc dich dung de ma hoa password khi tao mot tai khoan thi trong CSDL truong password
        /// se duoc ma hoa than du lieu kieu byte
        /// </summary>
        /// <param name="value">truyen gia tri vo chuoi nay</param>
        /// <returns></returns>
        public string GetMD5Hash(string value)
        {
            //MD5 su dung thu vien System.Security.Cryptography;
            MD5 md5Hasher = MD5.Create();
            byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(value));
            StringBuilder builder =new StringBuilder();
            for (int i = 0; i < data.Length; i++)
            {
                builder.Append(data[i].ToString("x2"));
            }
            return builder.ToString();
        }
    }
}